/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86186
 * Date: 2023-08-14
 * Time: 20:52
 */

class ListNode {
    int val;
    ListNode next;
    ListNode() {}
    ListNode(int val) { this.val = val; }
    ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}
public class Test {

    //leetcode 203 移除链表的元素
    public ListNode removeElements(ListNode head, int val) {
        if(head == null) return null;
        ListNode phead = new ListNode(-1);
        ListNode tmp = phead;
        ListNode cur = head;
        while(cur != null) {
            if(cur.val != val) {
                tmp.next = cur;
                tmp = tmp.next;
            }
            cur = cur.next;
        }
        tmp.next = null;

        return phead.next;
    }

}
